{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Python绘制中国地图和城市图表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyecharts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.7.1'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pyecharts.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Map"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1. 绘制中国城市数据图表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2019全国各省人口数量排名，前10个\n",
    "province_population = [\n",
    "    [\"广东\", 11169],\n",
    "    [\"山东\", 10005.83],\n",
    "    [\"河南\", 9559.13],\n",
    "    [\"四川\", 8302],\n",
    "    [\"江苏\", 8029.3],\n",
    "    [\"河北\", 7519.52],\n",
    "    [\"湖南\", 6860.2],\n",
    "    [\"安徽\", 6254.8],\n",
    "    [\"湖北\", 5902],\n",
    "    [\"浙江\", 5657]\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "map = (\n",
    "    Map()\n",
    "    .add(\"各省人口数量\", province_population, \"china\")\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"2019全国各省人口数量排名\"),\n",
    "        visualmap_opts=opts.VisualMapOpts(max_=12000),\n",
    "    )\n",
    ")\n",
    "map.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2. 绘制具体城市数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2019年北京各区人口数量，前5个\n",
    "beijing_district = [\n",
    "    [\"朝阳区\", 395.5],\n",
    "    [\"海淀区\", 369.4],\n",
    "    [\"丰台区\", 232.4],\n",
    "    [\"昌平区\", 196.3],\n",
    "    [\"大兴区\", 156.2],\n",
    "    [\"通州区\", 137.8],\n",
    "    [\"西城区\", 129.8],\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "map = (\n",
    "    Map()\n",
    "    .add(\"各区人口\", beijing_district, \"北京\")\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"2019年北京各区人口数量\"), \n",
    "        visualmap_opts=opts.VisualMapOpts(max_=400)\n",
    "    )\n",
    ")\n",
    "map.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
